//
//  ZPBFistPageControllerVC.m
//  WZLProduct
//
//  Created by dllo on 16/3/17.
//  Copyright © 2016年 HaiTeng. All rights reserved.
//

#import "ZPBFistPageControllerVC.h"
#import "ZPBSecondViewController.h"
#import "ZPBFistPageCollectionViewCell.h"
#import "RankButtonViewController.h"
#import "SongListViewController.h"
#import "RadioStationViewController.h"

#define KEYHEADER 0
@interface ZPBFistPageControllerVC ()<UICollectionViewDataSource, UICollectionViewDelegate, UIScrollViewDelegate, ZPBFistPageCollectionViewCellDelegate>

///选择标记的View;
@property (nonatomic, strong) UIView *bottomView;
///HOT按钮
@property (nonatomic, strong) UIButton *hotButton;
///NEW按钮
@property (nonatomic, strong) UIButton *nButton;
///HOT文字
@property (nonatomic, strong) UILabel *hotLabel;
///NEW文字
@property (nonatomic, strong) UILabel *nLabel;
///底部中心控制台
@property (nonatomic, strong) UIView *centerBottomView;
///底部collectionView
@property (nonatomic, strong) UICollectionView *collectionView;

@property (nonatomic, strong) NSMutableArray *SongListDataSouce;

@end

@implementation ZPBFistPageControllerVC

- (void)viewDidLoad {
    [super viewDidLoad];
    
    /**< 防止内置 */
    //    self.automaticallyAdjustsScrollViewInsets = NO;
    
    [self createBottomView];
    [self createCollectionView];
    [self createCenterBottomVIew];
    
    
}

// left 左 right 右

//代理方法帮助cell跳转
- (void)selectCell {
    
    RankButtonViewController *rankVc = [[RankButtonViewController alloc] init];
    
    [self.navigationController pushViewController:rankVc animated:YES];
}
- (void)selectCell2 {
    
    SongListViewController *songListVc = [[SongListViewController alloc] init];

    [self.navigationController pushViewController:songListVc animated:YES];
}

- (void)selectCell3 {
    RadioStationViewController *RadioVc = [[RadioStationViewController alloc] init];
    
    [self.navigationController pushViewController:RadioVc animated:YES];
}
- (void)viewWillAppear:(BOOL)animated {
    [super viewWillAppear:animated];
    self.navigationController.navigationBar.hidden = YES;
}

- (void)viewWillDisappear:(BOOL)animated {
    [super viewWillDisappear:animated];
    self.navigationController.navigationBar.hidden = NO;
}

- (void)createCenterBottomVIew {
    self.centerBottomView = [[UIView alloc] initWithFrame:CGRectMake(0, kScreenHeight - 69, kScreenWidth, 69)];
    _centerBottomView.backgroundColor = [UIColor blackColor];
    [self.view addSubview:_centerBottomView];
    
}


- (void)createCollectionView {
    UICollectionViewFlowLayout *layout = [[UICollectionViewFlowLayout alloc] init];
    layout.minimumInteritemSpacing = 0;
    layout.minimumLineSpacing = 0;
    layout.sectionInset = UIEdgeInsetsMake(0, 0, 0, 0);
    layout.itemSize = CGSizeMake(kScreenWidth , kScreenHeight);
    layout.scrollDirection = UICollectionViewScrollDirectionHorizontal;
    
    self.collectionView = [[UICollectionView alloc] initWithFrame:CGRectMake(0, 69, kScreenWidth, kScreenHeight - 69) collectionViewLayout:layout];
    self.collectionView.contentSize = CGSizeMake(kScreenWidth * 2, kScreenHeight);
    _collectionView.delegate = self;
    _collectionView.dataSource = self;
    _collectionView.pagingEnabled = YES;
    _collectionView.backgroundColor = [UIColor groupTableViewBackgroundColor];
    
    [_collectionView registerClass:[ZPBFistPageCollectionViewCell class] forCellWithReuseIdentifier:@"cell"];
    [self.view addSubview:_collectionView];
    [_collectionView registerClass:[UICollectionViewCell class] forCellWithReuseIdentifier:@"cell_2"];
}
//cell个数
- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section {
    return 2;
}

- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {
    UICollectionViewCell *cell2 = [collectionView dequeueReusableCellWithReuseIdentifier:@"cell_2" forIndexPath:indexPath];
    
    if (indexPath.row == 0) {
        
        return cell2;
    }else {
        ZPBFistPageCollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"cell" forIndexPath:indexPath];
        NSLog(@"2");
        cell.delegate = self;
        return cell;
        
    }
    
    
    return nil ;
}



- (void)createBottomView {
    
    self.hotButton = [UIButton buttonWithType:UIButtonTypeCustom];
    _hotButton.backgroundColor = [UIColor blackColor];
    [_hotButton addTarget:self action:@selector(hotButton:) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:_hotButton];
    [_hotButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.left.mas_offset(0);
        make.size.mas_offset(CGSizeMake(kScreenWidth / 2, 60));
    }];
    
    self.nButton = [UIButton buttonWithType:UIButtonTypeCustom];
    _nButton.backgroundColor = [UIColor blackColor];
    [_nButton addTarget:self action:@selector(newButton:) forControlEvents:UIControlEventTouchUpInside];
    
    [self.view addSubview:_nButton];
    [_nButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.right.mas_offset(0);
        make.size.mas_equalTo(_hotButton);
        
    }];
    
    self.hotLabel = [[UILabel alloc] init];
    _hotLabel.text = @"推荐";
    _hotLabel.textColor = [UIColor greenColor];
    _hotLabel.center = _hotButton.center;
    [_hotButton addSubview:_hotLabel];
    [_hotLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.center.equalTo(self.hotButton);
    }];
    
    self.nLabel = [[UILabel alloc] init];
    _nLabel.text = @"发现";
    _nLabel.textColor = [UIColor greenColor];
    _nLabel.center = _nButton.center;
    [_nButton addSubview: _nLabel];
    [_nLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.center.equalTo(self.nButton);
    }];
    
    self.bottomView = [[UIView alloc] init];
    _bottomView.backgroundColor = [UIColor greenColor];
    [self.view addSubview:_bottomView];
    
    [_bottomView mas_makeConstraints:^(MASConstraintMaker *make) {
        
        
        make.bottom.mas_equalTo(_hotButton);
        make.left.width.mas_equalTo(_hotLabel);
        make.height.offset(5);
        
    }];
    
}

//检测滑动控制view
- (void)scrollViewDidScroll:(UIScrollView *)scrollView {
    if (scrollView == _collectionView) {
        if (scrollView.contentOffset.x == 0) {
            [UIView animateWithDuration:0.3 animations:^{
                
                [_bottomView mas_remakeConstraints:^(MASConstraintMaker *make) {
                    
                    make.bottom.mas_equalTo(_hotButton);
                    make.left.width.mas_equalTo(_hotLabel);
                    make.height.offset(5);
                    
                }];
                
                 [self.view layoutIfNeeded];
            }];
        }else if(scrollView.contentOffset.x == kScreenWidth) {
            [UIView animateWithDuration:0.3 animations:^{
                
                [_bottomView mas_remakeConstraints:^(MASConstraintMaker *make) {
                    
                    
                    make.bottom.mas_equalTo(_nButton);
                    make.left.width.mas_equalTo(_nLabel);
                    make.height.offset(5);
                    
                }];
                 [self.view layoutIfNeeded];
                
            }];
            
        }
    }
}


//hot按钮
- (void)hotButton:(UIButton *)button {
    [UIView animateWithDuration:0.3 animations:^{
        [_bottomView mas_remakeConstraints:^(MASConstraintMaker *make) {
            
            
            make.bottom.mas_equalTo(_hotButton);
            make.left.width.mas_equalTo(_hotLabel);
            make.height.offset(5);
            
            
        }];
        [self.view layoutIfNeeded];
        
        [self.collectionView setContentOffset:CGPointMake( 0, 0)];
    }];
}
//new按钮x
- (void)newButton:(UIButton *)button {
    [UIView animateWithDuration:0.3 animations:^{
        [_bottomView mas_remakeConstraints:^(MASConstraintMaker *make) {
            
            
            make.bottom.mas_equalTo(_nButton);
            make.left.width.mas_equalTo(_nLabel);
            make.height.offset(5);
            
        }];
        [self.collectionView setContentOffset:CGPointMake(kScreenWidth, 0)];
        [self.view layoutIfNeeded];
        
    }];
    
}












@end






